package com.example.fresh_fruit.scheduled;

import com.example.fresh_fruit.service.PurchaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author :飞天の鱼
 * @date : 2022/8/24 16:47
 */

@Slf4j
@Component
public class Scheduler {

    @Autowired
    private PurchaseService purchaseService;

    private Integer time = 0;

//    @Scheduled(cron = "*/6 * * * * ?")   //定时器定义，设置执行时间
//    private void process() {
//        System.out.println("定时器执行"+time++);
//    }

    @Scheduled(cron = "0 23 15 * * ?")
    private void process1() {
        LocalDateTime startTime = LocalDateTime.now();
        //将生成采购表的方法放在此处，时间一到就会执行\
        int insertPurchase = purchaseService.insertPurchase(startTime);
//        log.info("采购单已生成完毕")
        if (insertPurchase != 0) {
            purchaseService.updataState();
            System.out.println("采购表已生成执行" + time++);
        }else {
            System.out.println("失败！");
        }

//        log.info("采购单状态已修改完毕")

    }

//    @Scheduled(fixedDelay = 1*1000)   //定时器定义，设置执行时间 1s
//    private void process2() {
//        System.out.println("定时器2执行"+time++);
//    }
}
